
gl data "D:\IFPRI\HarvestChoice\docs\data"

u "$data\cluster_aez.dta", clear

keep if ssa==1 & phs_l==1

encode AEZ_NAME, gen(AEZ)

gen 	AEZ_cat3=1 if AEZ>=1 & AEZ<=6
replace AEZ_cat3=2 if AEZ>=7 & AEZ<=10
replace AEZ_cat3=3 if AEZ>=11 & AEZ<=14
la de AEZ_cat3 1 Subtropic 2 "Tropic-cool" 3 "Tropic-warm"
la val AEZ_cat3 AEZ_cat3

gen 	AEZ_cat4=1 if AEZ==1 | AEZ==4 | AEZ==7 | AEZ==11
replace AEZ_cat4=2 if AEZ==2 | AEZ==5 | AEZ==9 | AEZ==13
replace AEZ_cat4=3 if AEZ==3 | AEZ==6 | AEZ==10 | AEZ==14
replace AEZ_cat4=4 if AEZ==8 | AEZ==12
la de AEZ_cat4 1 Arid 2 "Semi-arid" 3 "Sub-humid" 4 "Humid"
la val AEZ_cat4 AEZ_cat4

**** STUNTING ****
g ic_stntd_ari=ic_stntd_m*100 if AEZ_cat4==1
g ic_stntd_sem=ic_stntd_m*100 if AEZ_cat4==2
g ic_stntd_sub=ic_stntd_m*100 if AEZ_cat4==3
g ic_stntd_hum=ic_stntd_m*100 if AEZ_cat4==4

cumul ic_stntd_ari, gen(carid) 
cumul ic_stntd_sem, gen(csemiarid) 
cumul ic_stntd_sub, gen(csubhumid) 
cumul ic_stntd_hum, gen(chumid) 

preserve
stack carid ic_stntd_ari csemiarid ic_stntd_sem csubhumid ic_stntd_sub chumid ic_stntd_hum, into(c temp) wide clear
la var temp "percent of stunted children under 5"
tw mspline carid temp, lp(solid) || mspline csemiarid temp, lp(dash) || mspline csubhumid temp, lp(longdash) || mspline chumid temp, lp(shortdash) ///
leg(lab(1 Arid) lab(2 "Semi-arid") lab(3 "Sub-humid") lab(4 "Humid") span row(1)) yti(cumulative distribution) ti("Stunting distribution functions by AEZ") graphr(color(gs16))
gr export "$data\stunting_aez4.png", replace
restore

g ic_stntd_subt=ic_stntd_m*100 if AEZ_cat3==1
g ic_stntd_troc=ic_stntd_m*100 if AEZ_cat3==2
g ic_stntd_trow=ic_stntd_m*100 if AEZ_cat3==3

cumul ic_stntd_subt, gen(csubtropic) 
cumul ic_stntd_troc, gen(ctropicc) 
cumul ic_stntd_trow, gen(ctropicw) 


preserve
stack csubtropic ic_stntd_subt ctropicc ic_stntd_troc ctropicw ic_stntd_trow, into(c temp) wide clear
la var temp "percent of stunted children under 5"
tw mspline csubtropic temp, lp(solid) || mspline ctropicc temp, lp(dash) || mspline ctropicw temp, lp(longdash) ///
leg(lab(1 Subtropic) lab(2 "Tropic-cool") lab(3 "Tropic-warm") span row(1)) yti(cumulative distribution) ti("Stunting distribution functions by AEZ") graphr(color(gs16))
gr export "$data\stunting_aez3.png", replace
restore


drop carid-chumid csubtropic-ctropicw
**** WASTING ****
g ic_wstd_ari=ic_wstd_m*100 if AEZ_cat4==1
g ic_wstd_sem=ic_wstd_m*100 if AEZ_cat4==2
g ic_wstd_sub=ic_wstd_m*100 if AEZ_cat4==3
g ic_wstd_hum=ic_wstd_m*100 if AEZ_cat4==4

cumul ic_wstd_ari, gen(carid) 
cumul ic_wstd_sem, gen(csemiarid) 
cumul ic_wstd_sub, gen(csubhumid) 
cumul ic_wstd_hum, gen(chumid) 

preserve
stack carid ic_wstd_ari csemiarid ic_wstd_sem csubhumid ic_wstd_sub chumid ic_wstd_hum, into(c temp) wide clear
la var temp "percent of wasted children under 5"
tw mspline carid temp, lp(solid) || mspline csemiarid temp, lp(dash) || mspline csubhumid temp, lp(longdash) || mspline chumid temp, lp(shortdash) ///
leg(lab(1 Arid) lab(2 "Semi-arid") lab(3 "Sub-humid") lab(4 "Humid") span row(1)) yti(cumulative distribution) ti("Wasting distribution functions by AEZ") graphr(color(gs16))
gr export "$data\wasting_aez4.png", replace
restore

g ic_wstd_subt=ic_wstd_m*100 if AEZ_cat3==1
g ic_wstd_troc=ic_wstd_m*100 if AEZ_cat3==2
g ic_wstd_trow=ic_wstd_m*100 if AEZ_cat3==3

cumul ic_wstd_subt, gen(csubtropic) 
cumul ic_wstd_troc, gen(ctropicc) 
cumul ic_wstd_trow, gen(ctropicw) 

tabform ic_stntd_m ic_wstd_m using "$data\stunting_wasting.xls", by(AEZ_cat4) mt vert

preserve
stack csubtropic ic_wstd_subt ctropicc ic_wstd_troc ctropicw ic_wstd_trow, into(c temp) wide clear
la var temp "percent of wasted children under 5"
tw mspline csubtropic temp, lp(solid) || mspline ctropicc temp, lp(dash) || mspline ctropicw temp, lp(longdash) ///
leg(lab(1 Subtropic) lab(2 "Tropic-cool") lab(3 "Tropic-warm") span row(1)) yti(cumulative distribution) ti("Wasting distribution functions by AEZ") graphr(color(gs16))
gr export "$data\wasting_aez3.png", replace
restore
